#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>

int main(){
    int fd;
    off_t cur;
    char *fileNmePtr = "MyFile.txt";
    char *addString ="My added string!!!!";

    fd = open(fileNmePtr, O_WRONLY | O_APPEND);
    if(fd == -1){
        printf("Error open file %s %s", fileNmePtr, strerror(errno));
        exit(EXIT_FAILURE);
    }

    if( (cur = lseek(fd, 0, SEEK_SET)) == -1){
        printf("Error lseek file %s %s", fileNmePtr, strerror(errno));
        exit(EXIT_FAILURE);        
    }
    printf("Curren lseek = %ld\n", cur);
    if (write(fd, addString, strlen(addString)) == -1){
        printf("Error write to file %s %s", fileNmePtr, strerror(errno));
        exit(EXIT_FAILURE);           
    }

    if(close(fd) == -1){
        printf("Error close file %s %s", fileNmePtr, strerror(errno));
        exit(EXIT_FAILURE);          
    }

    exit(EXIT_SUCCESS);
}